<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 人员管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<link href="<%=basePath%>css/public.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/index.css" rel="stylesheet" type="text/css">

	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/userService.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/DatePicker/WdatePicker.js" defer="defer"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>

<div class="wrap100">

	<%@include file="/WEB-INF/jsp/include/left.jsp"%>	

	<!--right begin-->
    <div class="fl right">
 
 			<div class="full">
    
    		<!--产品详细信息 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>人员快速搜索</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>                
            </div>
            <div id="clear"></div>
            
            <div class="rightBorder">
            
            <form action="<%=basePath%>trade/userList" method="GET">
            <table width="75%" border="0" align="center" cellpadding="3" cellspacing="0">
              <tr>
                <td>人员姓名：                </td>
                <td><input size="25" class="input" type="text" name="userName" value="${searchCond.userName}"/>
                </td>
                <td>登录账号：</td>
                <td><input size="25" class="input" type="text" name="account" value="${searchCond.account}"/></td>
                <td>
                	<input type="submit" style="background:url(images/search.gif);width:92px;height:25px;border:0;margin:0;" value="" />
                </td>
              </tr>
            </table>
            </form>
      </div>
      
    		<!--人员分配 begin-->	
    		<div class="titleBg">
            	<div class="fl"><img src="images/rightTitleLeft.jpg" alt="left" /></div>
            	<div class="fl title"><span class="marking1"></span>人员管理</div>
                <div class="fr"><img src="images/rightTitleRight.jpg" alt="left" /></div>
            </div>
            <div id="clear"></div>
            
            <div class="rightPropertyList">
            	<div class="title1">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <tr>
                    <th width="5%" align="left"><input type="checkbox" name="allSelectId" id="allSelectId" onclick="judgmentChecjBox('allSelectId','id')" /></th>
                    <th width="10%" align="left" bgcolor="#f9f9f9">姓名</th>
             	    <th width="10%" align="left" bgcolor="#f9f9f9">部门</th>
                	<th width="10%" align="left" bgcolor="#f9f9f9">账号</th>
                    <th width="6%" align="left" bgcolor="#f9f9f9">业务代码</th>
                    <th width="5%" align="left" bgcolor="#f9f9f9">性别</th>                  
                    <th width="10%" align="left" bgcolor="#f9f9f9">电话</th>
                    <th width="10%" align="left" bgcolor="#f9f9f9">入职日期</th>
                    <th width="10%" align="left" bgcolor="#f9f9f9">角色权限</th>
                    <th width="7%" align="left" bgcolor="#f9f9f9">部门管理员</th>
                    <th width="10%" align="left" bgcolor="#f9f9f9">操作</th>                                   
                  </tr>
                </table>
              </div>
                <div class="list">
                <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#dfe5e9">
                  <c:forEach var="user" items="${userList}">
                  <tr>
                    <td width="5%" align="left"><input type="checkbox" value="${user.id}" name="id" /></td>
                    <td width="10%" align="left">${user.userName}</td>
                    <td width="10%" align="left">${user.department.deptName}</td>
                    <td width="10%" align="left">${user.account}</td>
                    <td width="6%" align="left">${user.code}</td>
                    <td width="5%" align="left">${user.sex==true?'男':'女'}</td>
                    <td width="10%" align="left">${user.telphone}</td>
                    <td width="10%" align="left"><fmt:formatDate value="${user.entryDate}" pattern="yyyy-MM-dd"/></td>
                    <td width="10%" align="left">${user.userType.text}</td>
                    <td width="7%" align="left">${user.isDeptAdmin==true?'是':'否'}</td>
                    <td width="10%" align="left">
	                  	<a href="javascript:;" onclick="delUser('${user.id}')">删除</a>
	                  	<a href="javascript:;" onclick="resetPass('${user.id}')">重置密码</a></td>
                  </tr>                  
                  </c:forEach>
				  <c:if test="${empty userList}"><tr><td colspan="11" style="text-align:center">没有相关记录！</td></tr></c:if>
              </table>
              </div>
            </div>
            <!--人员分配 end-->


            <!--统计 end-->
            <div class="total">
                <div class="fl Statistics">总数：<strong>${searchStat.totalCount} </strong> 条
                <script type="text/javascript">
				var pageControl = new wpagebar('pageControl');
				pageControl.argName = "pageIndex";
				pageControl.pageCount = ${searchStat.pageCount};
				pageControl.load();
				</script>
                </div>
                <div class="fr Operating">
                
                    <ul>
                        <li><input name="添 加" type="button" class="button" value="添 加" onclick="addUser()"/></li>
                        <li><input name="修 改" type="button" class="button" value="修 改" onclick="editUsers()"/></li>
                        <li><input name="删 除" type="button" class="button" value="删 除" onclick="delsellMultiple()"/></li>
                        
                    </ul>
                
                
                </div>
            </div>
 
            <!--统计 end-->
            
    </div>
	<!--right end-->
    <div id="win_temp" style="display:none">
	<div id="winCon_1">
	<table class="tabView" style="margin-top:5px">
		<tr><th width="100">姓名：</th><td><input type="text" name="userName0" id="userName0" value=""/>
			<input type="hidden" name="userId0" id="userId0" /></td>
			<th>性别：</th><td><input type="radio" name="sex0" checked="checked"/>男 <input type="radio" name="sex0"/>女 </td></tr>
		<tr><th>账号：</th><td><input type="text" name="account0" id="account0"/></td>
			<th>密码：</th><td><input type="password" name="password0" id="password0" value="111111"/><br/> <span style="color:blue">默认密码111111</span></td></tr>		
		<tr><th>业务代码：</th><td><input type="text" name="code0" id="code0" value=""/></td>
			<th>联系电话：</th><td><input type="text" name="telphone0" id="telphone0" value=""/></td></tr>
		<tr><th>Email：</th><td><input type="text" name="email0" id="email0" value=""/></td>
			<th>家庭地址：</th><td><input type="text" name="address0" id="address0" value=""/></td></tr>
		<tr><th>所属部门：</th><td>
			<select id="dept0">
			<c:forEach var="dept" items="${deptList}"><option value="${dept.id}">${dept.deptName}</option></c:forEach>
			</select></td>
			<th>角色权限：</th><td>
				<select id="type0">
				<c:forEach var="userType" items="${userType}">
				<option value="${userType.name}">${userType.text}</option>
				</c:forEach>
				</select>
			</td>
		</tr>
		<tr><th>&nbsp;</th><td>&nbsp;</td>
			<th>部门管理员：</th><td><input type="radio" name="isDeptAdmin0" />是 <input type="radio" name="isDeptAdmin0" checked="checked"/>否</td>
		</tr>
		</tr>
		<tr><th>状态：</th><td><input type="radio" name="status0" checked="checked"/>启用 <input type="radio" name="status0"/>禁用</td>
			<th>入职日期：</th><td><input type="text" name="entryDate0" id="entryDate0" value="" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td></tr>
		</tr>
		<tr><th>备注：</th><td colspan="3"><textarea name="detail0" id="detail0" rows="2" cols="50"></textarea> </td></tr>
		<tr><td colspan="2" style="text-align:right;height:">
			<input type="button" value=" 提 交 " class="btn1" onclick="submitUser()"/>
			<td colspan="2" style="text-align:left;height:"><input type="reset" value=" 重置 " class="btn1" value="reset"/></td>
			</td></tr>
	</table>
	</div>
</div>  
    <script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>
<script  type="text/javascript">
function addUser(){
	WIN.show('<font size=5>添加人员信息</font>',$('winCon_1'),{width:600,height:400});
}
function delsellMultiple(){			
	var objs = document.getElementsByName("id");
	var ids='';	
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids+=objs[i].value+",";
		}
	}
	if(ids==''){
		alert("请先选择要操作的信息");
		return ;
	}
	ids = ids.substring(0,ids.length - 1);
	
	if(confirm("您确定要删除?")){
		if(ids == ""){
			alert("请先选择要删除的信息！");
			return false;
		}else{
			userService.deleteUserByIds(ids,{
				callback:function(f){alert("删除成功");reload();},
				exceptionHandler:function(message){alert("删除失败，请重试");},
				errorHander:function(err){}
			})
		}
	}
}

function editUsers(){
	var objs = document.getElementsByName("id");	
	var ids=0;
	var vas='';
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			ids++;
			vas=objs[i].value;			
		}
	}
	if(ids!=1){
		alert("请选择一条且只能选择一条信息进行编辑！");
		return ;
	}	
	if(vas==''){
		alert("请先选择要操作的信息");
		return ;
	}else{
		editUser(vas);
	}	
}
function editUser(id){
	WIN.show('<font size=5>修改人员信息</font>',$('winCon_1'),{width:600,height:400});
	userService.getUserById(id,function(data){
		$('userId0').value=data.id;
		$('userName0').value=data.userName;
		if(data.sex){$N('sex0')[0].checked=true;}else{$N('sex0')[1].checked=true;}
		$('account0').value=data.account;
		$('password0').value=data.password;		
		$('telphone0').value=data.telphone;		
		$('dept0').value=data.department.id;		
		//$('role0').value=data.role.id;
		$('type0').value=data.userType;
		$('code0').value=data.code;		
		//if(data.isAdmin){$N('isAdmin0')[0].checked=true;}else{$N('isAdmin0')[1].checked=true;}
		if(data.isDeptAdmin){$N('isDeptAdmin0')[0].checked=true;}else{$N('isDeptAdmin0')[1].checked=true;}
		if(data.status){$N('status0')[0].checked=true;}else{$N('status0')[1].checked=true;}
		$('entryDate0').value=formatDate(data.entryDate);
		$('email0').value=data.email;
		$('address0').value=data.address;
		$('detail0').value=data.detail;	
	})
}
function delUser(id){
	if(confirm("删除用户，将导致用户无法登陆，确定删除 ？")){
		WIN.showpg();
		userService.deleteUserById(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}
/*重设置用户密码*/
function resetPass(id){
	if(id==null) alert("请选择要操作用用户!");
	if(confirm("确定重设置用户密码 ？")){
		WIN.showpg();
		userService.resetPassword(id,{
			callback:function(f){WIN.closepg();alert("操作成功，设置密码为111111 ");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("操作失败，请重试");},
			errorHander:function(err){}
		})
	}
}

function submitUser(){
	var user={
			id:			$('userId0').value,
			userName:	$('userName0').value,
			account:    $('account0').value,
			password:   $('password0').value,
			code:       $('code0').value,
			sex:		$N('sex0')[0].checked,
			telphone:	$('telphone0').value,
			email:      $('email0').value,
			address:    $('address0').value,
			department:	{id:$('dept0').value},
			//role:		{id:$('role0').value},
			userType:	$('type0').value,
			detail:	    $('detail0').value,
			status:		$N('status0')[0].checked,
			//isAdmin:    $N('isAdmin0')[0].checked,
			isDeptAdmin:$N('isDeptAdmin0')[0].checked,
			entryDate:  $('entryDate0').value.trim()?new Date($('entryDate0').value.trim().replace(/-/g,"/")):''				
	}
	
	if(''==user.account){alert('账号不能为空');return;}
	if(''==user.department.id){alert('请选择部门');return;}
	if(''==user.userType){alert('请选择角色权限');return;}
	if(''==user.code){alert('请指定业务代码');return;}	
	if(''==user.id){
		submitUser.user=user;		
		userService.existsAccount(user.account,{
			callback:function(f){
				if(f){alert('此账号已经存在，请更改为其它账号！');	}else{submit(submitUser.user);}
			},exceptionHandler:function(message){
				WIN.closepg();alert(message);alert("操作失败，请重试");reload();},errorHander:function(err){}
		})
	}else{
		submit(user);
	}
}
function submit(user){
	WIN.close();
	WIN.showpg();
	userService.existsCode(user,{
		callback:function(f){
			if(f){alert('此业务代码已经存在，请更改为其它代码！');	return}
		},exceptionHandler:function(message){
			WIN.closepg();alert(message);alert("操作失败，请重试");reload();},errorHander:function(err){}
		}
	);
		
	userService.editUser(user,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>
